package com.hlz.lib_x5;

import android.content.Context;
import android.util.Log;

import com.tencent.smtt.export.external.TbsCoreSettings;
import com.tencent.smtt.sdk.QbSdk;
import com.tencent.smtt.sdk.TbsListener;

import java.util.HashMap;

public class X5Utils {
    private static final String TAG = "X5Utils";

    // 在调用TBS初始化、创建WebView之前进行如下配置
    public static void initTbsSettings(Context context){
        // 在调用TBS初始化、创建WebView之前进行如下配置
        HashMap map = new HashMap();
        map.put(TbsCoreSettings.TBS_SETTINGS_USE_SPEEDY_CLASSLOADER, true);
        map.put(TbsCoreSettings.TBS_SETTINGS_USE_DEXLOADER_SERVICE, true);
        QbSdk.initTbsSettings(map);


        QbSdk.canLoadVideo(context);
        QbSdk.canLoadX5FirstTimeThirdApp(context);
        QbSdk.canGetDeviceId(true);
        QbSdk.canGetAndroidId(true);
        QbSdk.canLoadX5(context);
        QbSdk.canGetSubscriberId(true);

        QbSdk.setNeedInitX5FirstTime(true);
        QbSdk.setTbsLogClient(new MyTbsLogClient(context));

        QbSdk.initBuglyAsync(true);


        QbSdk.setTbsListener(new TbsListener() {
            @Override
            public void onDownloadFinish(int i) {
                Log.i(TAG, "onDownloadFinish: "+i);
            }

            @Override
            public void onInstallFinish(int i) {
                Log.i(TAG, "onInstallFinish: "+i);
            }

            @Override
            public void onDownloadProgress(int i) {
                Log.i(TAG, "onInstallFinish: "+i);
            }
        });


        QbSdk.initX5Environment(context, new QbSdk.PreInitCallback() {
            @Override
            public void onCoreInitFinished() {
                Log.i(TAG, "onCoreInitFinished: ");
            }

            @Override
            public void onViewInitFinished(boolean b) {
                Log.i(TAG, "onViewInitFinished: ");
            }
        });

        QbSdk.preInit(context, new QbSdk.PreInitCallback() {
            @Override
            public void onCoreInitFinished() {
                Log.i(TAG, "onCoreInitFinished: ");
            }

            @Override
            public void onViewInitFinished(boolean b) {
                Log.i(TAG, "onViewInitFinished: ");
            }
        });

    }
}
